<%@ page language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<%@ taglib prefix="ta" tagdir="/WEB-INF/tags/tatags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>接入系统编辑页面</title>
    <%@ include file="/ta/inc.jsp" %>
</head>
<body class="no-scrollbar">
<ta:pageloading/>
<ta:panel key="接入系统信息" fit="true" withButtonBar="true">
    <ta:text id="id" key="ID" display="false" value="${id}"/>
    <ta:text id="appid" key="系统ID" required="true" value="${sysAppVo.systemid}"/>
    <ta:text id="systemname" key="系统名称" required="true" value="${sysAppVo.systemname}"/>
    <ta:text id="sendertypeorder" key="渠道优先顺序" readOnly="true" required="true" value="${sysAppVo.senderTypeOrder}"/>
    <ta:text id="sendertypeorderdesc" key="渠道优先顺序" readOnly="true" required="true"
             value="${sysAppVo.senderTypeOrderDesc}"/>
    <ta:checkboxgroup id="qdbox" key="渠道" layout="column" cols="3" minSelect="1" maxSelect="6">
        <c:forEach items="${codeList}" var="item">
            <ta:checkbox key="${item.codeDESC}" value="${item.codeValue}" onClick="fnCheckClick(this)"/>
        </c:forEach>
    </ta:checkboxgroup>
    <ta:panelButtonBar align="right">
        <ta:button id="btnsubmit" key="提交" onClick="fnSave()"></ta:button>
    </ta:panelButtonBar>
</ta:panel>
</body>
</html>
<script type="text/javascript">
    $(document).ready(function () {
        $("body").taLayout();
        var senderTypeOrder = '${sysAppVo.senderTypeOrder}';
        var arr = senderTypeOrder.split(',')
        for (var i = 0; i < arr.length; i++) {
            var $obj = $("input[type='checkbox'][value='" + arr[i] + "']");
            $obj.parent().removeClass('ta-chk-uncheck');
            $obj.parent().addClass('ta-chk-checked');
        }
    });
    function fnCheckClick(obj) {
        var $this = $(obj);
        var $checkBox = $this.find("input[type='checkbox']")
        var sendertypeorder = $('#sendertypeorder').val();
        var sendertypeorderdesc = $('#sendertypeorderdesc').val();
        var codeDesc = $this.text().trim();
        var codeValue = $checkBox.val().trim();
        if ($checkBox.context.className.indexOf('ta-chk-checked') > 0) {
            if (sendertypeorder) {
                $('#sendertypeorder').val(sendertypeorder + "," + codeValue);
                $('#sendertypeorderdesc').val(sendertypeorderdesc + "," + codeDesc);
            } else {
                $('#sendertypeorder').val(codeValue);
                $('#sendertypeorderdesc').val(codeDesc);
            }
        } else if ($checkBox.context.className.indexOf('ta-chk-uncheck') > 0) {
            var afterS = codeValue + ",";
            var beforeS = "," + codeValue;
            if (sendertypeorder.indexOf(afterS) >= 0) {
                $('#sendertypeorder').val(sendertypeorder.replace(afterS, ""));
            } else if (sendertypeorder.indexOf(beforeS) >= 0) {
                $('#sendertypeorder').val(sendertypeorder.replace(beforeS, ""));
            } else {
                $('#sendertypeorder').val(sendertypeorder.replace(codeValue, ""));
            }
            var afterE = codeDesc + ",";
            var beforeE = "," + codeDesc;
            if (sendertypeorderdesc.indexOf(afterE) >= 0) {
                $('#sendertypeorderdesc').val(sendertypeorderdesc.replace(afterE, ""));
            } else if (sendertypeorderdesc.indexOf(beforeE) >= 0) {
                $('#sendertypeorderdesc').val(sendertypeorderdesc.replace(beforeE, ""));
            } else {
                $('#sendertypeorderdesc').val(sendertypeorderdesc.replace(codeDesc, ""));
            }
        }
    }

    function fnSave() {
        var appid = Base.getValue('appid');
        var systemname = $('#systemname').val();
        var sendertypeorder = $('#sendertypeorder').val();
        if (appid && systemname && sendertypeorder) {
            Base.submit("id,appid,systemname,sendertypeorder,sendertypeorderdesc", "<%=basePath%>sysAppManage/modify.do", null, "", false, function (data) {
                if (data.success) {
                    Base.alert("证书:" + data.fieldData.ticket, 'success', function () {
                        parent.Base.closeWindow('edit');
                    });
                } else {
                    Base.alert(data.message, "error");
                }
            });
        } else {
            Base.alert("请填写完整！", "error");
        }
    }

</script>
<%@ include file="/ta/incfooter.jsp" %>